﻿using DevTeam;
using Karbel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace DevTeamIT
{
    public class clsYetki
    {
        public List<int> U;
        public List<int> D;
        public clsYetki(List<int> Ux, List<int> Dx)
        {
            U = Ux;
            D = Dx;
        }
    }

    public class clsOncekiKonf
    {
        public string KonfNo;
        public DateTime KonfTarihi;
        public int CurrencyId;
        public int OdemeSekliId;
        public int OdemeTermini;
        public int TeslimSekliId;
        public int OngYuklemeSekliId;
        public int CarrierId;
    }

    public class clsOncekiYukleme
    {
        public DateTime YuklemeTarihi;
        public int AlisFaturasiId;
        public int YuklemeSekliId;
        public string IrsaliyeNo;
        public DateTime ETA;
    }

    public class Session
    {
        public static int SirketId = 0;
        public static clsOncekiKonf OncekiKonf;
        public static clsOncekiYukleme OncekiYukleme;

        public static Dictionary<int, clsYetki> ytkDict;
        public static bool ytk(int YetkiId)
        {
            if (isAdmin) 
                return true;
            else
            {
                if (ytkDict.ContainsKey(YetkiId))
                {
                    clsYetki val = ytkDict[YetkiId];
                    return val.U.Contains(Session.CurrentUser.UserId) ||
                        val.D.Contains(Session.CurrentUser.DepartmentId);
                }
                else
                    return false;
            }
        }

        public class LookupMapClass
        {
            public int LookupId;
            public string Caption, CaptionEN, CaptionIT;

            public LookupMapClass(int LookupId, string Caption)
            {
                this.LookupId = LookupId;
                this.Caption = Caption;
            }
        }

        public static Dictionary<string, LookupMapClass> LookupDict = new Dictionary<string, LookupMapClass>();

        public static bool NotificationsEnabled = true;

        public static User CurrentUser { get; set; }

        public static bool AmI(params int[] UserIds)
        {
            return UserIds.Contains(CurrentUser.UserId);
        }

        public static bool isAdmin
        {
            get { return Admins.Contains(CurrentUser.UserId); }
        }

        public static bool isDeveloper
        {
            get { return Developers.Contains(CurrentUser.InitialUserId); }
        }

        public static bool Notifications = true;

        public static int WhoAmI { get { return CurrentUser.UserId; } }

        public static int MyDept { get { return CurrentUser.DepartmentId; } }

        public static int[] Admins;
        public static int[] Developers;

        public static void SetAdmins(params int[] UserIds)
        {
            Admins = UserIds;
        }

        public static void SetDevelopers(params int[] UserIds)
        {
            Developers = UserIds;
        }

        static DataManager dataManager = null;

        static string gununKurlari;

        public static void Init(string ApplicationName, DataManager AppDataManager)
        {
            //Kasım'ın yapısından önceki sürüm
            //Speech.Speak("SPEECH");
            //string path = Path.GetTempFileName();
            //AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ConfExpert";
            //if (!Directory.Exists(AppDataPath))
            //    Directory.CreateDirectory(AppDataPath);
            //Aşağıdaki parçacık design time da static constructor larda yaşanan sorunları bertaraf etmesi için gerekli.            
            //if (LicenseManager.UsageMode == LicenseUsageMode.Runtime)

            //Orhan Abi'nin yapısından önceki sürüm :)
            //TempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "ConfExpert")).FullName;
            //AppDataPath = Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ConfExpert")).FullName;

            TempDirectory = FileManager.CreateTempFolder(ApplicationName);
            AppDataPath = FileManager.CreateAppDataFolder(ApplicationName);
            DataManager = AppDataManager;
        }

        public static double Usd, Eur, Gbp;

        public static string DebugInfo { get; set; }


        static DateTime dtStart;
        static string watcherName;

        public static void AddDebugInfo(string Info)
        {
#if (DEBUG)
            DebugInfo += Info + Environment.NewLine;
            Debug.WriteLine(Info);
#endif
        }

        public static void StopWatcher()
        {
            AddDebugInfo(watcherName + ":\t" + (DateTime.Now - dtStart).TotalMilliseconds + " (ms)");
        }

        public static void StartWatcher(string Name)
        {
            if (dtStart != null)
                StopWatcher();

            dtStart = DateTime.Now;
            watcherName = Name;
        }



        public static string BarkodEkle;
        public static string ScannerDeviceId;
        public static int DataFileSize;

        public static double AcilisSuresi;
        public static DateTime LaunchingTime;

        public static bool InvalidateStoklar = false;

        public static string sqlitefile;
        public static string sqlitefileDelete;
        public static int gleSeason, gleVendor, gleCustomer;

        public static string GununKurlari { get; set; }

        static public DataManager DataManager { get; set; }

        public static string Version { get; set; }

        public static string DatabaseName { get; set; }

        public static string TempDirectory { get; set; }

        public static string AppDataPath { get; set; }

        public static string SonArama { get; set; }

        public static string ServerAddress { get; set; }

        public static string ApplicationName { get; set; }

        public static string MessengerUserName { get; set; }

        public static string MessengerPassword { get; set; }

        public static string InfomobilUsername { get; set; }

        public static string InfomobilPassword { get; set; }
    }
}
